from selenium.webdriver.common.by import By
from utils.log_utils import logger
from page_object.base_page import BasePage


class AddMemberPage(BasePage):
    __INPUT_USERNAME = (By.ID, "username")
    __INPUT__ACCTID = (By.ID, "memberAdd_acctid")
    __INPUT_PHONE = (By.ID, "memberAdd_phone")
    __INPUT_INVITE = (By.XPATH, "//*[text()='通过邮件或短信发送企业邀请']/../input")
    __BTN_SAVE = (By.CSS_SELECTOR, ".js_btn_save")

    def fill_in_info(self, name, user_name, phone_number):
        logger.info(f"正在填写成员信息，成员姓名是：{name}")

        self.do_send_keys(name, self.__INPUT_USERNAME)
        self.do_send_keys(user_name, self.__INPUT__ACCTID)
        self.do_send_keys(phone_number, self.__INPUT_PHONE)
        self.do_find(self.__INPUT_INVITE).click()
        self.do_finds(self.__BTN_SAVE)[0].click()

        from page_object.contacts_page import ContactsPage
        return ContactsPage(self.driver)
